package com.novel.utils;
import com.novel.constants.ResultEnum;

/**
 * 统一返回结果工具类
 *
 * @author tanghao
 * @date 2021/08/06
 */
public class ResultVoUtil {


    public static ResultVO<?> success(Object object) {
        ResultVO<Object> resultVO = new ResultVO<>();
        resultVO.setData(object);
        resultVO.setCode(ResultEnum.SUCCESS.getCode());
        resultVO.setMessage(ResultEnum.SUCCESS.getMessage());
        return resultVO;
    }

    public static ResultVO<?> success() {
        return result(ResultEnum.SUCCESS);
    }

    public static ResultVO<?> failure() {
        return result(ResultEnum.FAILURE);
    }

    public static ResultVO<?> error(Integer code, String msg) {
        ResultVO<?> resultVO = new ResultVO<>();
        resultVO.setData(null);
        resultVO.setCode(code);
        resultVO.setMessage(msg);
        return resultVO;
    }

    public static ResultVO<?> result(ResultEnum resultEnum) {
        ResultVO<?> resultVO = new ResultVO<>();
        resultVO.setData(null);
        resultVO.setCode(resultEnum.getCode());
        resultVO.setMessage(resultEnum.getMessage());
        return resultVO;
    }

}